# 按摩项目后端服务启动脚本
Write-Host "========================================" -ForegroundColor Green
Write-Host "按摩项目后端服务启动脚本" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""

Write-Host "[1/3] 激活虚拟环境..." -ForegroundColor Yellow
& ".\venv\Scripts\Activate.ps1"

if ($LASTEXITCODE -ne 0) {
    Write-Host "错误：虚拟环境激活失败" -ForegroundColor Red
    Write-Host "请检查venv目录是否存在" -ForegroundColor Red
    Read-Host "按回车键退出"
    exit 1
}

Write-Host "[2/3] 检查数据库..." -ForegroundColor Yellow
python manage.py migrate --check

if ($LASTEXITCODE -ne 0) {
    Write-Host "警告：数据库需要迁移" -ForegroundColor Yellow
    Write-Host "正在执行迁移..." -ForegroundColor Yellow
    python manage.py migrate
}

Write-Host "[3/3] 启动Django服务..." -ForegroundColor Yellow
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host "后端服务地址: http://localhost:8000" -ForegroundColor Cyan
Write-Host "按 Ctrl+C 停止服务" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Green
Write-Host ""

python manage.py runserver

